package com.swingson.componentprocessor.impl;

import com.swingson.SwingsonGui;
import com.swingson.componentprocessor.BaseProcessor;
import com.swingson.exceptions.ErrorMessageException;
import com.swingson.exceptions.SwingsonException;
import com.swingson.jsonparser.JsonObject;
import java.awt.Component;
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;

public class JSplitPaneProcessor extends BaseProcessor {
private class DummyJButton extends JButton{

}
    @Override
    public JComponent createComponent(JsonObject jsonElement, JComponent parent, SwingsonGui gui) {
        JSplitPane split = new JSplitPane();
        split.setLeftComponent(new DummyJButton());
        split.setRightComponent(new DummyJButton());
        return split;
    }

    @Override
    public Class[] getProcessingClass() {
        return new Class[]{JSplitPane.class};
    }

    
    @Override
    public void addCompomentToThis(Container parent, Component child, Object layoutParameter) {
        JSplitPane split=(JSplitPane)parent;
        if(split.getLeftComponent() instanceof DummyJButton){
            split.setLeftComponent(child);
        }else if(split.getRightComponent() instanceof DummyJButton){
            split.setRightComponent(child);
        }else{
            throw new SwingsonException("You cannot add more than two components to splitpane");
        }
    }
}
